package com.autologistics.util;

import java.util.List;

import com.autologistics.model.Admin;
import com.autologistics.model.Disparter;
import com.autologistics.model.Goods;
import com.autologistics.model.Media;
import com.autologistics.model.Machine;
import com.autologistics.model.Ordertable;
import com.autologistics.model.User;

public class PageBean {
	
	List<Goods> goodsList;
	List<Media> mediaList;
	List<Ordertable> ordertableList;
	List<Disparter> disparterList;
	List<Machine> machineList;
	List<User> userList;
	List<Admin> adminList;
	private int allRow;//all row in database
	private int totalPage;//
	private int currentPage;
	private int pageSize;
	private boolean isFirstPage;
	private boolean isLastPage;
	private boolean hasPreviousPage;
	private boolean hasLastPage;
	private boolean hasNextPage;
	
	
	public List<Media> getMediaList() {
		return mediaList;
	}
	public void setMediaList(List<Media> mediaList) {
		this.mediaList = mediaList;
	}
	
	public List<User> getUserList() {
		return userList;
	}
	public void setUserList(List<User> userList) {
		this.userList = userList;
	}
	public List<Admin> getAdminList() {
		return adminList;
	}
	public void setAdminList(List<Admin> adminList) {
		this.adminList = adminList;
	}
	public List<Disparter> getDisparterList() {
		return disparterList;
	}
	public void setDisparterList(List<Disparter> disparterList) {
		this.disparterList = disparterList;
	}
	public List<Machine> getMachineList() {
		return machineList;
	}
	public void setMachineList(List<Machine> machineList) {
		this.machineList = machineList;
	}
	public List<Ordertable> getOrdertableList() {
		return ordertableList;
	}
	public void setOrdertableList(List<Ordertable> ordertableList) {
		this.ordertableList = ordertableList;
	}
	public List<Goods> getGoodsList() {
		return goodsList;
	}
	public void setGoodsList(List<Goods> goodsList) {
		this.goodsList = goodsList;
	}
	public int getAllRow() {
		return allRow;
	}
	public void setAllRow(int allRow) {
		this.allRow = allRow;
	}
	public int getTotalPage() {
		return totalPage;
	}
	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}
	public int getCurrentPage() {
		return currentPage;
	}
	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public boolean isFirstPage() {
		return isFirstPage;
	}
	public void setFirstPage(boolean isFirstPage) {
		this.isFirstPage = isFirstPage;
	}
	public boolean isLastPage() {
		return isLastPage;
	}
	public void setLastPage(boolean isLastPage) {
		this.isLastPage = isLastPage;
	}
	public boolean isHasPreviousPage() {
		return hasPreviousPage;
	}
	public void setHasPreviousPage(boolean hasPreviousPage) {
		this.hasPreviousPage = hasPreviousPage;
	}
	public boolean isHasLastPage() {
		return hasLastPage;
	}
	public void setHasLastPage(boolean hasLastPage) {
		this.hasLastPage = hasLastPage;
	}
	public boolean isHasNextPage() {
		return hasNextPage;
	}
	public void setHasNextPage(boolean hasNextPage) {
		this.hasNextPage = hasNextPage;
	}
	
	
    /** 
     * 计算总页数  静态方法 
     * @param pageSize  每页的记录数 
     * @param allRow  总记录数 
     * @return 总页数 
         */  
    public static int countTotalPage(final int pageSize,final int allRow){  
        int totalPage = allRow % pageSize == 0 ? allRow/pageSize : allRow/pageSize + 1;  
        return totalPage;  
    } 
    
    /** 
     * 计算当前页开始的记录 
     * @param pageSize 每页记录数 
     * @param currentPage 当前第几页 
     * @return 当前页开始记录号 
     */  
    public static int countOffset(final int pageSize,final int currentPage){  
	    final int offset = pageSize * (currentPage - 1);  
	    return offset;  
    }  
	
    /** 
     * 计算当前页，若为0或者请求的URL中没有“?page = ”则用1代替 
     * @param page 传入的参数（可能为空，即0  则返回1） 
     * @return 
     */  
    public static int countCurrentPage(int page){  
	    final int curpage = (page == 0 ? 1 : page);  
	    return curpage;  
    }   
}
